<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">

    <style>
        .layui-hide{  /*最后的pic为字段的field*/
            height: 100%;
            max-width: 100%;
        }
        .layui-table-cell{
            height:auto !important;
        }
    </style>
</head>
<body>



<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">订单管理</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">


                        {if !empty($order)}
                        <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>

                            <div class="layui-input-block">
                                <select name="order_sn" lay-verify="" lay-search id="order_sn">
                                    <option value="">请选择</option>
                                    {foreach $order as $k=>$v}
                                    <option value="{$v['order_sn']}">{$v['order_sn']}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {/if}
                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="gtour_title" id="gtour_title" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单状态</label>
                            <div class="layui-input-block">
                                <select name="activity_column" lay-filter="aihao" id="order_status">
                                    <option value=""></option>

                                    <option value="3">待评价</option>
                                    <option value="4">完成</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline" >
                            <label class="layui-form-label">订单时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="search_start_time" name="search_start_time">

                            </div>

                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>

                       <!--  <div class="layui-inline" style="float: right">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="excel">
                                   导出
                                </button>
                            </div>
                        </div> -->
                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate" lay-size="lg">



                    </table>
                    <script type="text/html" id="test-pass">

                    </script>
                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="appDetail">评价信息</a> 

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="appDetail" style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group"> 
       <input type="hidden" id="app_id" name="app_id">
        <div class="layui-form-item">  
            <div class="layui-inline">
                <label class="layui-form-label">评价人：</label>
                <div class="layui-input-block">
                    <input type="text"  id="nicknames" autocomplete="off" class="layui-input">
                </div>
            </div>
             <div class="layui-inline">
                <label class="layui-form-label">评价时间：</label>
                <div class="layui-input-block">
                    <input type="text" id='create_times' autocomplete="off" class="layui-input">
                </div>
            </div> 
        </div>

        <div class="layui-form-item"> 
               <div class="layui-inline">
                <label class="layui-form-label">评价星级：</label>
                <div class="layui-input-block">
                   <input type="text" id="star" autocomplete="off" class="layui-input">
                </div>
            </div> 
             <div class="layui-inline">
                <label class="layui-form-label">评价状态：</label>
                <div class="layui-input-block">
                    <input type="text" id='eval_status' autocomplete="off" class="layui-input">
                </div>
            </div> 
        </div>    


          <div class="layui-form-item">   
           <div class="layui-inline">
                <label class="layui-form-label">评价内容：</label>
                <div class="layui-input-block"> 
                    <textarea id="contents" style="width: 500px;height: 150px;border: none;">
                        
                    </textarea>
                </div>
            </div> 
        </div> 
            <div class="layui-form-item">   
           <div class="layui-inline">
                <label class="layui-form-label">评价图片：</label>
                <div class="layui-input-block" id="images"> 
                    <img src="">
                </div>
            </div> 

        </div> 
         
    </form>
</div> 
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set','layedit','upload'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate,
            upload = layui.upload
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Order/order')}"
            ,height: 'full-100'
            ,cols: [[
                {field:'order_id',align:"center",title: '订单ID'}
                ,{field:'order_sn',align:"center",title: '订单编号'}
                 ,{field:'gtour_title',align:"center",title: '商品名称'}
                ,{field:'linkman',align:"center",title: '取票人姓名'}
                ,{field:'tel',align:"center",title: '取票人手机号'}
                ,{field:'order_price',align:"center",title: '订单价格'}
                ,{field:'pay_type',align:"center",title: '支付方式',templet:function(d){
                        if(d.pay_type == 1){
                            return "支付宝";
                        }else if (d.pay_type == 2){
                            return "微信";
                        }
                    }}
                ,{field:'order_status',align:"center",title: '订单状态',templet:function(d){
                        if (d.order_status == 3){
                            return "待评价";
                        }else if(d.order_status == 4){
                            return "已完成";
                        }
                    }}
                ,{field:'create_time',align:"center",title: '下订单时间'}
                ,{field:'admin_rename',align:"center",title: '核销人'}
                ,{field:'time',align:"center",title: '核销时间'}
                ,{align:'center',width:350, title: '操作', toolbar: '#test-table-operate-barDemo'}

            ]]
            ,page: true
            ,limit: 20
        });

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });
        var search_start = laydate.render({ //活动开始
            elem: '#search_start_time',
            range:'~'

        });
        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;

            if(obj.event === 'showImg') {
                if (!data.images) {
                    layer.msg('暂无图片', {time: 1000});
                    return false;
                }
                var img_src = data.images;
                var img_src_arr = img_src.split(',');

                var img_src_data = {};
                img_src_data.title = '评价图片';
                img_src_data.id = data.id;
                img_src_data.start = 0;
                img_src_data.data = [];

                var src = {};

                for (var i = 0; i < img_src_arr.length; i++) {
                    src = {};
                    var num = i + 1;
                    src.alt = '评价图片' + num;
                    src.pid = i;
                    src.src = img_src_arr[i];
                    src.thumb = img_src_arr[i];
                    console.log(src);
                    img_src_data.data.push(src);
                }
                console.log(img_src_data);
                layer.photos({
                    photos: img_src_data
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
            else if(obj.event === 'del'){
                layer.confirm('确认删除此评价吗？', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: "{:url('Appraise/delAppraise')}",
                        type: 'post',
                        dataType: 'json',
                        data: {id:data.app_id},
                        success: function(msg){
                            layer.close(loading);
                            if (msg.code == 0) {
                                obj.del();
                                layer.close(index);
                            }else{
                                layer.msg(msg.message,{icon:2,time:1000});
                            }
                        }
                    });
                });
            }else if(obj.event === 'appDetail'){
                 var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var order_id = data.order_id;

                $.ajax({
                    url: "{:url('Order/getAppInfo')}",
                    type: 'post',
                    dataType: 'json',
                    data: {order_id:order_id,type:3},
                    success: function(data){
                        layer.close(loading);
                        if (data.code === 1) {
                            if(data.data.nickname==""){
                                $('#nicknames').val('未设置');
                            }else{
                                $('#nicknames').val(data.data.nickname);
                            } 
                             if(data.data.create_time==""){
                                $('#create_times').val('未设置');
                            }else{
                                $('#create_times').val(data.data.create_time);
                            } 
                             if(data.data.star==""){
                                $('#star').val('未设置');
                            }else{
                                $('#star').val(data.data.star);
                            } 
                            if(data.data.app_id){
                                $('#app_id').val(data.data.app_id);
                            }
                             if(data.data.eval_status==""){
                                $('#eval_status').val('未设置');
                            }else{
                                $('#eval_status').val(data.data.eval_status);
                            } 
                             if(data.data.content==""){
                                $('#contents').val('未设置');
                            }else{
                                $('#contents').val(data.data.content);
                            }   
                            
                             if(data.data.images.length>0){ 
                                 var imagehtml = "";
                                 $("#images").html('');
                                for(var i=0;i<data.data.images.length;i++){
                                     imagehtml += "<img style='margin-right:5px' width='100px' height='100px' src="+data.data.images[i]+">";
                                } 
                            }else{
                                 $('#images').html('未设置'); 
                            }
                           $("#images").append(imagehtml); 
                          $("#editIsMenu input:radio[value ="+data.data.is_display+"]").attr('checked','true');
                            var userDetailModal = layer.open({
                                title:'旅行社评价详情'
                                ,type: 1
                                ,shadeClose: true
                                ,area:['800px']
                                ,content: $('#appDetail')
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:1000});
                        }


                    }
                })
            }
        });




        var $ = layui.$, active = {
            searchUserButton:function(){
                var order_sn  = $('#order_sn').val();

                var gtour_title = $('#gtour_title').val();
                var order_status = $('#order_status').val();
                var search_start_time  = $('#search_start_time').val();
                table.reload('test-table-operate', {
                    where: {
                        order_sn:order_sn,
                        gtour_title:gtour_title,
                        order_status:order_status,
                        search_start_time:search_start_time,
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            },
            excel:function () {
                window.location.href ="{:url('Order/excel')}"
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });

    //格式化时间函数
    function Format(datetime,fmt) {
        if (parseInt(datetime)==datetime) {
            if (datetime.length==10) {
                datetime=parseInt(datetime)*1000;
            } else if(datetime.length==13) {
                datetime=parseInt(datetime);
            }
        }
        datetime=new Date(datetime);
        var o = {
            "M+" : datetime.getMonth()+1,                 //月份
            "d+" : datetime.getDate(),                    //日
            "h+" : datetime.getHours(),                   //小时
            "m+" : datetime.getMinutes(),                 //分
            "s+" : datetime.getSeconds(),                 //秒
            "q+" : Math.floor((datetime.getMonth()+3)/3), //季度
            "S"  : datetime.getMilliseconds()             //毫秒
        };
        if(/(y+)/.test(fmt))
            fmt=fmt.replace(RegExp.$1, (datetime.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)
            if(new RegExp("("+ k +")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        return fmt;
    }
</script>

</body>
</html>